/**
 * 
 */
package org.carabiner.infinitest;

import java.awt.Color;

import javax.swing.Icon;
import javax.swing.ImageIcon;

class ResultTreeNode extends TestTreeNode
{
  static final Color ERROR_COLOR = new Color(0xb22222);
  
  private Icon errorIcon;
  private Icon failureIcon;
  
  public ResultTreeNode(TestEvent testEvent)
  {
    super(testEvent);
    setAllowsChildren(false);
    errorIcon = new ImageIcon(ResultTreeNode.class.getResource("error.png"));
    failureIcon = new ImageIcon(ResultTreeNode.class.getResource("failure.png"));
  }
  
  public boolean isNodeForEvent(TestEvent e)
  {
    return super.isNodeForEvent(e) && 
        e.getTestMethod().equals(getTestEvent().getTestMethod());
  }
  
  public String getToolTip()
  {
    if (getTestEvent().getError() == null)      
      return null;
    return InfinitestUtils.stackTraceToString(getTestEvent().getError().getStackTrace());
  }
  
  public String toString()
  {
    String baseText = getTestEvent().getTestMethod().toString() + ": ";
    if (getTestEvent().getError() != null &&
        !getTestEvent().isFailure())
      return baseText +
             getTestEvent().getError().getClass().getName() + 
             "(" + 
             getTestEvent().getMessage() +
             ")";    
    return baseText + getTestEvent().getMessage();
  }

  @Override
  public Icon getIcon()
  {
    return super.getIcon();
  }
  
  @Override
  public Color getColor()
  {   
    if (getTestEvent().isFailure())
      return Color.RED;
    return ERROR_COLOR;
  }
  
  
  
  
}